<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>合伙人管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header table-operate-btn">
							<button class="layui-btn layui-btn-normal layui-btn-sm" type="add">添加</button>
							<!--<button class="layui-btn layui-btn-danger layui-btn-sm" data-type='off'>一键禁用</button>
							<button class="layui-btn layui-btn-container layui-btn-sm" data-type='on'>一键启用</button>-->
						</div>
						<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<!-- <button class="layui-btn layui-btn-primary search_inline" type="add">添加</button> -->
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="会员编号" name="member_id" id="member_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">合伙人类型</label>
									<div class="layui-input-block">
										<select name="type" lay-verify="required" lay-filter="select1" id="select1">
											<option value=""></option>
											<option value="1">天使合伙人</option>
											<option value="2">业务合伙人</option>
											<option value="3">事业合伙人</option>
											<!-- <option value="4">城市合伙人</option> -->
										</select>
									</div>
								</div>
								
								<div class="layui-inline search_inline">
									<label class="layui-form-label">用户编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="用户编号" name="user_id" id="user_id" autocomplete="off">
									</div>
								</div>
								

								<div class="layui-inline search_inline">
									<label class="layui-form-label">姓名、手机号</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="keyword" placeholder="姓名、手机号" name="keyword" autocomplete="off">
									</div>
								</div>
								
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->
							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
							<script type="text/html" id="test-table-operate-barDemo1"> 
								{{# if(d.status_pay==2&&d.status > 0&&d.status < 3){ }}
									<a class="layui-btn layui-btn-default layui-btn-xs" lay-event="audit">划拨</a>
								{{# } }} 
								<!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a> -->
								<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">修改</a> 
							<!-- 	{{# if(d.status == 1){ }}
									<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable">禁用</a>
								{{# } }} -->
									
							</script>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				parent_id: getParam('id')
			}
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'treeGrid'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					treeGrid = layui.treeGrid,
					admin = layui.admin;

				console.log(_data)
				initdata();

				function initdata() {
					_data['parent_id'] = getParam('id')
					table.render({
						elem: '#test-table-operate',
						url: server.shop_copartner_list,
						height: 'full-115',
						cellMinWidth: cellMinWidth,
						limit: limit,
						limits: limits,
						defaultToolbar: [  'exports', {
							title: '提示' //标题
							, layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
							, icon: 'layui-icon-tips' //图标类名
						}],
						toolbar: true,
						cols: [
							[{
									width: 70,
									type: 'numbers',
									title: '序号',
									fixed: 'left',
								}, 
								{
									width: 150,
									align: 'center',
									fixed: 'right',
									toolbar: '#test-table-operate-barDemo1',
									title: '划拨',
									fixed: 'left'
								}, {
									width: 100,
									field: 'status',
									title: '订单状态',
									fixed: 'left',
									templet: function(d) {
										let statusname  ='';
										if(d.status == 0){
											statusname = '已取消';
										}else if(d.status == 1){
											statusname = '等待划拨';
										}else if(d.status == 2){
											statusname = '划拨中';
										}else if(d.status == 3){
											statusname = '划拨完成';
										}
										return statusname
									}
								},  
								{
									width: 100,
									field: 'status_pay',
									title: '支付状态',
									fixed: 'left',
									templet: function(d) {
										let statusname  ='';
										if(d.status_pay == 0){
											statusname = '已取消';
										}else if(d.status_pay == 1){
											statusname = '待支付';
										}else if(d.status_pay == 2){
											statusname = '已支付';
										}
										return statusname
									}
								},  
								{
									field: 'amount',
									title: '金额',
									sort: true									
								},
								{
									field: 'addtime',
									title: '申请时间',
									width: 200,
								},
								{
									field: 'quantity',
									title: '购买数量',
								},
								{
									field: 'gave_quantity',
									title: '已划拨数量',
								},
								{
									field: 'gavetime',
									title: '划拨时间',
									width: 200,
								},
								
		// 						{
		// 							width: 120,
		// 							field: 'type',
		// 							title: '服务类型',
		// 							fixed: 'left',
		// 							templet: function(d){
		// 								var type = d.type;
		// 								if(type) {
		// 									var type_leng = type.split(',');
		// 									var type_show = ''
		// 									for(var i = 0; i < type_leng.length; i++) {
		// 										if(type_leng.length-1 == i){
		// 											type_show += service_type_show(1, type_leng[i])
		// 										}else{
		// 											type_show += service_type_show(1, type_leng[i])+','
		// 										}
		// 									}	
		// 									return type_show
		// 								} else {
		// 									return ''
		// 								}
		
										
		// 							}
		// 						},
								{
									field: 'memberid',
									title: '会员编号',
									sort: true									
								}, {
									field: 'userid',
									title: '用户编号',
									sort: true									
								},{
									field: 'name',
									width: 180,
									title: '合伙人姓名'
								},
								{
									field: 'type',
									width: 180,
									title: '合伙人类型',
									templet: function(d) {
										let statusname  ='';
										if(d.type == 0){
											statusname = '';
										}else if(d.type == 1){
											statusname = '天使合伙人';
										}else if(d.type == 2){
											statusname = '业务合伙人';
										}else if(d.type == 3){
											statusname = '事业合伙人';
										}
										return statusname
									}
								},
								{
									field: 'mobile',
									title: '手机号码'
								},
								{
									field: 'remark',
									width: 180,
									title: '备注'
								}
							]
						],
						page: true,
						where: _data,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							console.log('res', res)
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.shop_copartner?.pager.total, //解析数据长度
								"data": res.shop_copartner?.data //解析数据列表
							};
						}
					});
				}

				$('#add').on('click', function() {
					layer.open({
						type: 2,
						title: '添加',
						shadeClose: true,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['750px', '700px'],
						content: 'model/edit_add.html?customerid=' + $("#customerid").val(),
						end: function() {

						}
					});
				});

				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					_data = data.field
					initdata();
					return false;
				});

				$("button[type=reset]").on("click", function() {
					_data = {}
					initdata();
					document.getElementById("form").reset();
				});
				
				$("button[type=add]").on("click", function() {
					// layer.open({
					// 	type: 2,
					// 	title: '划拨',
					// 	shadeClose: false,
					// 	shade: 0.5,
					// 	area: ['1200px', '800px'],
					// 	content: 'model/edit_add_audit.html?id=' + data.id,
					// 	end: function() {}
					// });
					layer.open({
						type: 2,
						title: '添加',
						shadeClose: true,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['90%', '90%'],
						content: 'model/add.html',
						end: function() {
					
						}
					});
					// _data = {}
					// initdata();
					// document.getElementById("form").reset();
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});

				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if (obj.event === 'edit') {
						layer.open({
							type: 2,
							title: '修改',
							shadeClose: true,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['90%', '90%'],
							// content: 'model/edit_add.html?id=' + data.id,
							content: 'model/add.html?id=' + data.id,
							end: function() {

							}
						});
					} else if (obj.event === 'audit') {
						layer.open({
							type: 2,
							title: '划拨',
							shadeClose: false,
							shade: 0.5,
							area: ['1200px', '800px'],
							content: 'model/edit_add_audit.html?id=' + data.id,
							end: function() {}
						});
					}else if (obj.event === 'delete') { 
						// layer.confirm('确定要删除所选的数据？删除之后该团长将会变成普通用户!', function() {
						// 	$.ajax({
						// 		url: shop_leader_delete,
						// 		type: 'post',
						// 		dataType: 'json',
						// 		data: "id=" + data.id,
						// 		success: function(data) {
						// 			if (data.code == '0') {
						// 				layer.msg('删除成功');
						// 				initdata()
						// 			} else {
						// 				layer.msg('删除失败');
						// 			}
						// 		},
						// 		'error': function() {
						// 			layer.msg('系统错误');
						// 		}
						// 	})
						// });
					}
					else if (obj.event === 'disable') { 
						layer.confirm('确定要禁用该合伙人？', function() {
							$.ajax({
								url: server.shop_leader_disable,
								type: 'post',
								dataType: 'json',
								data: "id=" + data.id,
								success: function(data) {
									if (data.code == '0') {
										layer.msg('禁用成功');
										initdata()
									} else {
										layer.msg('禁用失败');
									}
								},
								'error': function() {
									layer.msg('系统错误');
								}
							})
						});
					}
					
					
					
				});

				//删除
				$('#del').on('click', function() {
					var checkStatus = table.checkStatus('test-table-operate'),
						data = JSON.stringify(checkStatus.data);
					var id = "";
					for (var i = 0; i < checkStatus.data.length; i++) {
						id += checkStatus.data[i].id;
						if (i != checkStatus.data.length - 1) {
							id += ",";
						}
					}
					layer.confirm('确定要删除所选的' + checkStatus.data.length + '条数据？', function() {
						$.ajax({
							url: server.shop_leader_delete,
							type: 'post',
							dataType: 'json',
							data: "id=" + id,
							success: function(data) {
								if (data.code == '0') {
									layer.msg('删除成功');
									initdata()
								} else {
									layer.msg('删除失败');
								}
							},
							'error': function() {
								layer.msg('系统错误');
							}
						})
					});
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

			});
		</script>
	</body>

</html>
